package com.gxa.worker.recycling.service.impl;

import com.gxa.core.recycling.pojo.Goods;
import com.gxa.core.recycling.pojo.Imgs;
import com.gxa.worker.recycling.repository.GoodsRepository;
import com.gxa.worker.recycling.repository.ImgsRepository;
import com.gxa.worker.recycling.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：looker
 * @date ：Created in 2021/12/3 15:33
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    GoodsRepository goodsRepository;

    @Autowired
    ImgsRepository imgsRepository;

    @Override
    public List<Map<String, Object>> getAll() {
        List<Map<String,Object>> list = new ArrayList<>();
        List<Goods> allByStateEquals = goodsRepository.findAllByStateEquals(true);
        for (int i = 0; i < allByStateEquals.size(); i++) {
            HashMap<String, Object> map = new HashMap<>();
            Goods goods = allByStateEquals.get(i);
            map.put("good",goods);
            List<Imgs> imgs = imgsRepository.findAllByGidEquals(goods.getId());
            map.put("imgs",imgs);
            list.add(map);
        }
        return list;
    }
}
